import 'package:flutter/material.dart';
import 'package:tender_flutter/constant/theme_colors.dart';
import 'package:tender_flutter/http/api_response.dart';
import 'package:tender_flutter/style/font_style.dart';
import 'package:tender_flutter/utils/screen_adaper.dart';
import 'package:tender_flutter/utils/toast.dart';
import 'package:tender_flutter/utils/utils.dart';
import 'package:tender_flutter/widgets/base_appbar.dart';

import 'api/api_person.dart';

class TiXianPage extends StatefulWidget {
  final String money;

  const TiXianPage({Key key, this.money}) : super(key: key);

  @override
  _TiXianPageState createState() => _TiXianPageState();
}

class _TiXianPageState extends State<TiXianPage> {
  // String selImg = RPath.imgPath + "icon_box_sel.png";
  // String norImg = RPath.imgPath + "icon_box_nor.png";

  /// 提现渠道
  // int _payChannel = AppConstant.PAY_CHANNEL_WX;

  String _money, _aliAccount;

  /// 提现
  Future _startTiXian() async {
    if (isEmpty(_money)) {
      ToastUtils.show("请输入提现金额");
      return;
    }
    if (isEmpty(_aliAccount)) {
      ToastUtils.show("请输入支付宝账号");
      return;
    }
    ToastUtils.showLoading("");
    var response = await ApiPerson.tiXian(money: _money, account: _aliAccount);
    ToastUtils.dismissLoading();
    if (response.status == Status.SUCCESS) {
      ToastUtils.show("提现申请成功");
    }
  }

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomPadding: false,
      backgroundColor: ThemeColors.colorWhite,
      appBar: _initAppBar(),
      body: _initBody(),
    );
  }

  /// 导航
  Widget _initAppBar() {
    return BaseAppBar(
      context,
      Text("提现", style: FonStyle.navTextStyle()),
      backgroundColor: ThemeColors.colorWhite,
    );
  }

  /// 内容体
  Widget _initBody() {
    return Column(children: [
      Container(
          padding: EdgeInsets.symmetric(
              vertical: ScreenAdapter.height(60),
              horizontal: ScreenAdapter.width(40)),
          child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text("提现金额(元)",
                    style: TextStyle(
                        color: ThemeColors.colorType14,
                        fontSize: ScreenAdapter.sp(32))),
                Row(children: [
                  Text("¥",
                      style: TextStyle(
                          color: ThemeColors.colorType1,
                          fontSize: ScreenAdapter.sp(40),
                          fontWeight: FontWeight.bold)),
                  SizedBox(width: ScreenAdapter.width(10)),
                  Expanded(
                      child: TextField(
                    decoration: InputDecoration(
                        hintText: "输入金额", border: InputBorder.none),
                    style: TextStyle(
                        color: ThemeColors.colorType1,
                        fontSize: ScreenAdapter.sp(40),
                        fontWeight: FontWeight.bold),
                    textAlign: TextAlign.left,
                    autofocus: false,
                    keyboardType: TextInputType.number,
                    onChanged: (value) {
                      _money = value;
                    },
                  ))
                ]),
                TextField(
                  decoration: InputDecoration(
                      hintText: "输入提现支付宝账号",
                      labelText: "支付宝账号",
                      border: InputBorder.none),
                  style: TextStyle(
                    color: ThemeColors.colorType4,
                    fontSize: ScreenAdapter.sp(32),
                  ),
                  textAlign: TextAlign.left,
                  autofocus: false,
                  keyboardType: TextInputType.emailAddress,
                  onChanged: (value) {
                    _aliAccount = value;
                  },
                ),
              ])),

      // Padding(
      //   padding: EdgeInsets.symmetric(horizontal: ScreenAdapter.width(30)),
      //   child: Column(
      //     mainAxisAlignment: MainAxisAlignment.start,
      //     crossAxisAlignment: CrossAxisAlignment.start,
      //     mainAxisSize: MainAxisSize.min,
      //     children: [
      //       Padding(
      //           padding:
      //               EdgeInsets.symmetric(vertical: ScreenAdapter.height(30)),
      //           child: Text("选择提现方式",
      //               style: TextStyle(
      //                 color: ThemeColors.colorType1,
      //                 fontSize: ScreenAdapter.sp(32),
      //               ))),
      //       Divider(height: 1, color: ThemeColors.colorType49),
      //       Padding(
      //           padding:
      //               EdgeInsets.symmetric(vertical: ScreenAdapter.height(30)),
      //           child: InkWell(
      //               onTap: () {
      //                 setState(() {
      //                   _payChannel = AppConstant.PAY_CHANNEL_WX;
      //                 });
      //               },
      //               child: Row(children: [
      //                 Image.asset(RPath.imgPath + "icon_pay_wx.png",
      //                     width: ScreenAdapter.width(40),
      //                     height: ScreenAdapter.width(40)),
      //                 SizedBox(width: ScreenAdapter.width(20)),
      //                 Text("微信",
      //                     style: TextStyle(
      //                       color: ThemeColors.colorType1,
      //                       fontSize: ScreenAdapter.sp(32),
      //                     )),
      //                 Expanded(child: SizedBox()),
      //                 Image.asset(
      //                     _payChannel == AppConstant.PAY_CHANNEL_WX
      //                         ? selImg
      //                         : norImg,
      //                     width: ScreenAdapter.width(40),
      //                     height: ScreenAdapter.width(40)),
      //               ]))),
      //       Divider(height: 1, color: ThemeColors.colorType49),
      //       Padding(
      //           padding:
      //               EdgeInsets.symmetric(vertical: ScreenAdapter.height(30)),
      //           child: InkWell(
      //               onTap: () {
      //                 setState(() {
      //                   _payChannel = AppConstant.PAY_CHANNEL_ALi;
      //                 });
      //               },
      //               child: Row(children: [
      //                 Image.asset(RPath.imgPath + "icon_pay_ali.png",
      //                     width: ScreenAdapter.width(40),
      //                     height: ScreenAdapter.width(40)),
      //                 SizedBox(width: ScreenAdapter.width(20)),
      //                 Text("支付宝支付",
      //                     style: TextStyle(
      //                       color: ThemeColors.colorType1,
      //                       fontSize: ScreenAdapter.sp(32),
      //                     )),
      //                 Expanded(child: SizedBox()),
      //                 Image.asset(
      //                     _payChannel == AppConstant.PAY_CHANNEL_ALi
      //                         ? selImg
      //                         : norImg,
      //                     width: ScreenAdapter.width(40),
      //                     height: ScreenAdapter.width(40)),
      //               ]))),
      //       Divider(height: 1, color: ThemeColors.colorType49),
      //     ],
      //   ),
      // ),
      SizedBox(height: ScreenAdapter.height(200)),
      Container(
          height: ScreenAdapter.height(100),
          width: double.infinity,
          margin: EdgeInsets.symmetric(horizontal: ScreenAdapter.width(30)),
          decoration: BoxDecoration(
              color: ThemeColors.colorType6,
              borderRadius: BorderRadius.circular(ScreenAdapter.width(50))),
          child: FlatButton(
              onPressed: () {
                _startTiXian();
              },
              child: Text("提现",
                  style: TextStyle(
                      color: ThemeColors.colorWhite,
                      fontSize: ScreenAdapter.sp(32))))),
      SizedBox(height: ScreenAdapter.height(30)),

      Container(
          padding: EdgeInsets.symmetric(horizontal: ScreenAdapter.width(40)),
          child: RichText(
              text: TextSpan(
                  text: '* ',
                  style: TextStyle(
                      fontSize: ScreenAdapter.sp(24),
                      color: ThemeColors.colorType30,
                      fontWeight: FontWeight.bold),
                  children: <TextSpan>[
                TextSpan(
                    text: "提现申请提交后，会在3个工作日内打款至绑定的支付宝账号，如有异常请联系客服。",
                    style: TextStyle(
                      fontSize: ScreenAdapter.sp(24),
                      color: ThemeColors.colorType14,
                    )),
              ])))
    ]);
  }
}
